package org.example.threadlocaltest.demos.configure;

import jodd.util.ThreadUtil;
import org.example.threadlocaltest.demos.eneity.domain.MyStudent;
import org.example.threadlocaltest.demos.eneity.service.MyStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class LogEvent {

    @Autowired//这里一般都是 logService 我这里就随便写一个
    private MyStudentService myStudentService;

    //指定线程池
    @Async("threadPoolExecutor")
    public void log(String message) {
        //模拟耗时操作 休眠3秒
        ThreadUtil.sleep(3000);
        MyStudent myStudent = new MyStudent();
        myStudent.setAge(18);
        myStudent.setName("登录日志");
        myStudentService.save(myStudent);
    }


}
